//
//  PersonalDataCell.swift
//  Eternity
//
//  Created by cll12_12 on 2016/12/13.
//  Copyright © 2016年 ZhengWei. All rights reserved.
//

import UIKit

class PersonalDataCell: UITableViewCell {

    // MARK: - life cycle
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        initBaseLayout()
        layoutPageSubviews()
        self.selectionStyle = .none
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - private method
    func initBaseLayout() {
        self.addSubview(titleLabel)
        self.addSubview(headImageView)
        self.addSubview(arrowImageView)
        self.addSubview(nameLabel)
        self.addSubview(phoneLabel)
    }
    
    func layoutPageSubviews() {
        titleLabel.snp.makeConstraints { (make) in
            make.left.equalTo(self).offset(14)
            make.centerY.equalTo(self)
            make.width.equalTo(50)
            make.height.equalTo(14)
        }
        
        headImageView.snp.makeConstraints { (make) in
            make.right.equalTo(self).offset(-32)
            make.centerY.equalTo(self)
            make.width.height.equalTo(56)
        }
        
        arrowImageView.snp.makeConstraints { (make) in
            make.right.equalTo(self).offset(-16)
            make.centerY.equalTo(self)
            make.width.equalTo(6)
            make.height.equalTo(12)
        }
        
        nameLabel.snp.makeConstraints { (make) in
            make.right.equalTo(self).offset(32)
            make.centerY.equalTo(self)
            make.width.equalTo(100)
            make.height.equalTo(14)
        }
        
        phoneLabel.snp.makeConstraints { (make) in
            make.right.equalTo(self).offset(-14)
            make.centerY.equalTo(self)
            make.width.equalTo(103)
            make.height.equalTo(14)
        }
    }
    
    func configUI() {
        nameLabel.text = "陈妞妞"
        phoneLabel.text = "188****1210"
    }
    
    // MARK: - setters and getters
    var _index: Int?
    var index: Int? {
        set {
            if newValue == 0 {
                headImageView.isHidden = false
                arrowImageView.isHidden = false
                nameLabel.isHidden = true
                phoneLabel.isHidden = true
                titleLabel.text = "头像"
            } else if newValue == 1 {
                nameLabel.isHidden = false
                arrowImageView.isHidden = false
                headImageView.isHidden = true
                phoneLabel.isHidden = true
                titleLabel.text = "昵称"
             } else {
                phoneLabel.isHidden = false
                nameLabel.isHidden = true
                arrowImageView.isHidden = true
                headImageView.isHidden = true
                titleLabel.text = "手机号"
            }
        } get {
            return _index
        }
    }
    
    var _titleLabel: UILabel!
    var titleLabel: UILabel {
        if _titleLabel == nil {
            _titleLabel = UILabel()
            _titleLabel.font = UIFont(name: "PingFang-SC-Regular", size: 14)
            _titleLabel.textColor = UIColor(hexString: "#252525")
        }
        return _titleLabel
    }
    
    var _headImageView: UIImageView!
    var headImageView: UIImageView {
        if _headImageView == nil {
            _headImageView = UIImageView()
            _headImageView.image = UIImage(named: "icon_personalmin")
        }
        return _headImageView
    }
    
    var _arrowImageView: UIImageView!
    var arrowImageView: UIImageView {
        if _arrowImageView == nil {
            _arrowImageView = UIImageView()
            _arrowImageView.image = UIImage(named: "icon_arrow_r")
        }
        return _arrowImageView
    }
    
    var _nameLabel: UILabel!
    var nameLabel: UILabel {
        if _nameLabel == nil {
            _nameLabel = UILabel()
            _nameLabel.textColor = UIColor(hexString: "#666666")
            _nameLabel.font = UIFont(name: "PingFang-SC-Regular", size: 14)
        }
        return _nameLabel
    }
    
    var _phoneLabel: UILabel!
    var phoneLabel: UILabel {
        if _phoneLabel == nil {
            _phoneLabel = UILabel()
            _phoneLabel.font = UIFont(name: "SFNSText", size: 13)
            _phoneLabel.textColor = UIColor(hexString: "#666666")
            _phoneLabel.textAlignment = .right
        }
        return _phoneLabel
    }
}
